<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学生学号" prop="studentId">
        <el-input v-model="queryParams.studentId" placeholder="请输入学生学号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="序号" prop="sfId">
        <el-input v-model="queryParams.sfId" placeholder="请输入序号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="学校全称" prop="schoolName">
        <el-input v-model="queryParams.schoolName" placeholder="请输入学校全称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="院系全称" prop="departmentName">
        <el-input v-model="queryParams.departmentName" placeholder="请输入院系全称" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="学段性质" prop="academicStage">
        <el-select v-model="queryParams.academicStage" placeholder="请选择学段性质" clearable>
          <el-option v-for="dict in dict.type.academic_stage" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="专业" prop="major">
        <el-input v-model="queryParams.major" placeholder="请输入专业" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="学历层次" prop="educationLevel">
        <el-select v-model="queryParams.educationLevel" placeholder="请选择学历层次" clearable>
          <el-option v-for="dict in dict.type.education_leve" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="学制期" prop="studyDuration">
        <el-input v-model="queryParams.studyDuration" placeholder="请输入学制期" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="入学时间" prop="enrollmentDate">
        <el-date-picker clearable v-model="queryParams.enrollmentDate" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择入学时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="性别" prop="gender">
        <el-select v-model="queryParams.gender" placeholder="请选择性别" clearable>
          <el-option v-for="dict in dict.type.sys_user_sex" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="民族" prop="ethnicity">
        <el-select v-model="queryParams.ethnicity" placeholder="请选择民族" clearable>
          <el-option v-for="dict in dict.type.nation" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="政治面貌" prop="politicalStatus">
        <el-select v-model="queryParams.politicalStatus" placeholder="请选择政治面貌" clearable>
          <el-option v-for="dict in dict.type.party_type" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="身份证号码" prop="idCardNumber">
        <el-input v-model="queryParams.idCardNumber" placeholder="请输入身份证号码" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="家庭所在地" prop="homeLocation">
        <el-input v-model="queryParams.homeLocation" placeholder="请输入家庭所在地" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="申请贫困类型" prop="povertyType">
        <el-select v-model="queryParams.povertyType" placeholder="请选择申请贫困类型" clearable>
          <el-option v-for="dict in dict.type.poverty_type" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="申请贫困类型补充说明" prop="otherDifficultyType">
        <el-select v-model="queryParams.otherDifficultyType" placeholder="请选择申请贫困类型补充说明" clearable>
          <el-option v-for="dict in dict.type.other_poverty_difficulty_type" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="困难等级" prop="difficultyLevel">
        <el-select v-model="queryParams.difficultyLevel" placeholder="请选择困难等级" clearable>
          <el-option v-for="dict in dict.type.difficulty_level" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="国家助学金等级" prop="scholarshipLevel">
        <el-select v-model="queryParams.scholarshipLevel" placeholder="请选择国家助学金等级" clearable>
          <el-option v-for="dict in dict.type.scholarship_level" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="国家助学金金额" prop="scholarshipAmount">
        <el-input v-model="queryParams.scholarshipAmount" placeholder="请输入国家助学金金额" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="是否为扩招生" prop="isExpansion">
        <el-select v-model="queryParams.isExpansion" placeholder="请选择是否为扩招生" clearable>
          <el-option v-for="dict in dict.type.sys_yes_no" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="是否为退役士兵" prop="isVeteran">
        <el-select v-model="queryParams.isVeteran" placeholder="请选择是否为退役士兵" clearable>
          <el-option v-for="dict in dict.type.sys_yes_no" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="是否为公费师范生等定向培养" prop="isScholarship">
        <el-select v-model="queryParams.isScholarship" placeholder="请选择是否为公费师范生等定向培养" clearable>
          <el-option v-for="dict in dict.type.sys_yes_no" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="定向培养类型" prop="orientationType">
        <el-input v-model="queryParams.orientationType" placeholder="请输入定向培养类型" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="未资助原因" prop="fundingReason">
        <el-input v-model="queryParams.fundingReason" placeholder="请输入未资助原因" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="审核状态" prop="auditStatus">
        <el-select v-model="queryParams.auditStatus" placeholder="请选择审核状态" clearable>
          <el-option v-for="dict in dict.type.audit_status" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="拒绝原因" prop="rejectionReason">
        <el-input v-model="queryParams.rejectionReason" placeholder="请输入拒绝原因" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="用户ID" prop="userId">
        <el-input v-model="queryParams.userId" placeholder="请输入用户ID" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="部门ID" prop="deptId">
        <el-input v-model="queryParams.deptId" placeholder="请输入部门ID" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="最后更新时间" prop="lastUpdateTime">
        <el-date-picker clearable v-model="queryParams.lastUpdateTime" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择最后更新时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['studentFinancial:studentFinancial:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['studentFinancial:studentFinancial:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['studentFinancial:studentFinancial:remove']">删除</el-button>
      </el-col>
      <!-- 审核   -->
      <el-col :span="1.5">
        <el-button type="info" icon="el-icon-check" size="mini" @click="openAuditDialog" :disabled="multiple"
          v-hasPermi="['system:check']" plain>审核</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['studentFinancial:studentFinancial:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 确保visible是通过sync双向绑定 -->
    <!-- 审核 -->
    <audit-dialog :visible.sync="auditDialogVisible" table_name="jw_courses" id_name="course_id" ref="audit"
      @submit="handleAuditSubmit" />
    <el-table v-loading="loading" :data="studentFinancialList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="学生学号" align="center" prop="studentId" />
      <el-table-column label="序号" align="center" prop="sfId" />
      <el-table-column label="学校全称" align="center" prop="schoolName" />
      <el-table-column label="院系全称" align="center" prop="departmentName" />
      <el-table-column label="学段性质" align="center" prop="academicStage">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.academic_stage" :value="scope.row.academicStage" />
        </template>
      </el-table-column>
      <el-table-column label="专业" align="center" prop="major" />
      <el-table-column label="学历层次" align="center" prop="educationLevel">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.education_leve" :value="scope.row.educationLevel" />
        </template>
      </el-table-column>
      <el-table-column label="学制期" align="center" prop="studyDuration" />
      <el-table-column label="入学时间" align="center" prop="enrollmentDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.enrollmentDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="性别" align="center" prop="gender">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.gender" />
        </template>
      </el-table-column>
      <el-table-column label="民族" align="center" prop="ethnicity">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.nation" :value="scope.row.ethnicity" />
        </template>
      </el-table-column>
      <el-table-column label="政治面貌" align="center" prop="politicalStatus" />
      <el-table-column label="身份证号码" align="center" prop="idCardNumber" />
      <el-table-column label="家庭所在地" align="center" prop="homeLocation" />
      <el-table-column label="申请贫困类型" align="center" prop="povertyType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.poverty_type" :value="scope.row.povertyType" />
        </template>
      </el-table-column>
      <el-table-column label="申请贫困类型补充说明" align="center" prop="otherDifficultyType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.other_poverty_difficulty_type" :value="scope.row.otherDifficultyType" />
        </template>
      </el-table-column>
      <el-table-column label="困难等级" align="center" prop="difficultyLevel">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.difficulty_level" :value="scope.row.difficultyLevel" />
        </template>
      </el-table-column>
      <el-table-column label="国家助学金等级" align="center" prop="scholarshipLevel">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.scholarship_level" :value="scope.row.scholarshipLevel" />
        </template>
      </el-table-column>
      <el-table-column label="国家助学金金额" align="center" prop="scholarshipAmount" />
      <el-table-column label="是否为扩招生" align="center" prop="isExpansion">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.isExpansion" />
        </template>
      </el-table-column>
      <el-table-column label="是否为退役士兵" align="center" prop="isVeteran">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.isVeteran" />
        </template>
      </el-table-column>
      <el-table-column label="是否为公费师范生等定向培养" align="center" prop="isScholarship">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.isScholarship" />
        </template>
      </el-table-column>
      <el-table-column label="定向培养类型" align="center" prop="orientationType" />
      <el-table-column label="未资助原因" align="center" prop="fundingReason" />
      <el-table-column label="审核状态" align="center" prop="auditStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.audit_status" :value="scope.row.auditStatus" />
        </template>
      </el-table-column>
      <el-table-column label="拒绝原因" align="center" prop="rejectionReason" />
      <el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column label="部门ID" align="center" prop="deptId" />
      <el-table-column label="最后更新时间" align="center" prop="lastUpdateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lastUpdateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['studentFinancial:studentFinancial:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['studentFinancial:studentFinancial:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改学生资助信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="学生学号" prop="studentId">
          <el-input v-model="form.studentId" placeholder="请输入学生学号" />
        </el-form-item>
        <el-form-item label="学校全称" prop="schoolName">
          <el-input v-model="form.schoolName" placeholder="请输入学校全称" />
        </el-form-item>
        <el-form-item label="院系全称" prop="departmentName">
          <el-input v-model="form.departmentName" placeholder="请输入院系全称" />
        </el-form-item>
        <el-form-item label="学段性质" prop="academicStage">
          <el-select v-model="form.academicStage" placeholder="请选择学段性质">
            <el-option v-for="dict in dict.type.academic_stage" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="专业" prop="major">
          <el-input v-model="form.major" placeholder="请输入专业" />
        </el-form-item>
        <el-form-item label="学历层次" prop="educationLevel">
          <el-select v-model="form.educationLevel" placeholder="请选择学历层次">
            <el-option v-for="dict in dict.type.education_leve" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学制期" prop="studyDuration">
          <el-input v-model="form.studyDuration" placeholder="请输入学制期" />
        </el-form-item>
        <el-form-item label="入学时间" prop="enrollmentDate">
          <el-date-picker clearable v-model="form.enrollmentDate" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择入学时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="性别" prop="gender">
          <el-select v-model="form.gender" placeholder="请选择性别">
            <el-option v-for="dict in dict.type.sys_user_sex" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="民族" prop="ethnicity">
          <el-select v-model="form.ethnicity" placeholder="请选择民族">
            <el-option v-for="dict in dict.type.nation" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="政治面貌" prop="politicalStatus">
          <el-select v-model="queryParams.politicalStatus" placeholder="请选择政治面貌" clearable>
            <el-option v-for="dict in dict.type.party_type" :key="dict.value" :label="dict.label" :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="身份证号码" prop="idCardNumber">
          <el-input v-model="form.idCardNumber" placeholder="请输入身份证号码" />
        </el-form-item>
        <el-form-item label="家庭所在地" prop="homeLocation">
          <el-input v-model="form.homeLocation" placeholder="请输入家庭所在地" />
        </el-form-item>
        <el-form-item label="申请贫困类型" prop="povertyType">
          <el-select v-model="form.povertyType" placeholder="请选择申请贫困类型">
            <el-option v-for="dict in dict.type.poverty_type" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="申请贫困类型补充说明" prop="otherDifficultyType">
          <el-select v-model="form.otherDifficultyType" placeholder="请选择申请贫困类型补充说明">
            <el-option v-for="dict in dict.type.other_poverty_difficulty_type" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="困难等级" prop="difficultyLevel">
          <el-select v-model="form.difficultyLevel" placeholder="请选择困难等级">
            <el-option v-for="dict in dict.type.difficulty_level" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="国家助学金等级" prop="scholarshipLevel">
          <el-select v-model="form.scholarshipLevel" placeholder="请选择国家助学金等级">
            <el-option v-for="dict in dict.type.scholarship_level" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="国家助学金金额" prop="scholarshipAmount">
          <el-input v-model="form.scholarshipAmount" placeholder="请输入国家助学金金额" />
        </el-form-item>
        <el-form-item label="是否为扩招生" prop="isExpansion">
          <el-select v-model="form.isExpansion" placeholder="请选择是否为扩招生">
            <el-option v-for="dict in dict.type.sys_yes_no" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否为退役士兵" prop="isVeteran">
          <el-select v-model="form.isVeteran" placeholder="请选择是否为退役士兵">
            <el-option v-for="dict in dict.type.sys_yes_no" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否为公费师范生等定向培养" prop="isScholarship">
          <el-select v-model="form.isScholarship" placeholder="请选择是否为公费师范生等定向培养">
            <el-option v-for="dict in dict.type.sys_yes_no" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="定向培养类型" prop="orientationType">
          <el-input v-model="form.orientationType" placeholder="请输入定向培养类型" />
        </el-form-item>
        <el-form-item label="未资助原因" prop="fundingReason">
          <el-input v-model="form.fundingReason" placeholder="请输入未资助原因" />
        </el-form-item>
        <el-form-item label="审核状态" prop="auditStatus">
          <el-select v-model="form.auditStatus" placeholder="请选择审核状态">
            <el-option v-for="dict in dict.type.audit_status" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="拒绝原因" prop="rejectionReason">
          <el-input v-model="form.rejectionReason" placeholder="请输入拒绝原因" />
        </el-form-item>
        <el-form-item label="用户ID" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户ID" />
        </el-form-item>
        <el-form-item label="部门ID" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入部门ID" />
        </el-form-item>
        <el-form-item label="最后更新时间" prop="lastUpdateTime">
          <el-date-picker clearable v-model="form.lastUpdateTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择最后更新时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listStudentFinancial, getStudentFinancial, delStudentFinancial, addStudentFinancial, updateStudentFinancial } from "@/api/studentFinancial/studentFinancial";
import AuditDialog from '@/components/AuditDialog/AuditDialog.vue'; // 引入审核子组件
export default {
  name: "StudentFinancial",
  dicts: ['poverty_type', 'academic_stage', 'difficulty_level', 'party_type', 'sys_yes_no', 'scholarship_level', 'audit_status', 'sys_user_sex', 'other_poverty_difficulty_type', 'nation', 'education_leve'],
  components: { AuditDialog },
  data() {
    return {
      // 控制审核对话框的显示
      auditDialogVisible: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学生资助信息表格数据
      studentFinancialList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        studentId: null,
        sfId: null,
        schoolName: null,
        departmentName: null,
        academicStage: null,
        major: null,
        educationLevel: null,
        studyDuration: null,
        enrollmentDate: null,
        name: null,
        gender: null,
        ethnicity: null,
        politicalStatus: null,
        idCardNumber: null,
        homeLocation: null,
        povertyType: null,
        otherDifficultyType: null,
        difficultyLevel: null,
        scholarshipLevel: null,
        scholarshipAmount: null,
        isExpansion: null,
        isVeteran: null,
        isScholarship: null,
        orientationType: null,
        fundingReason: null,
        auditStatus: null,
        rejectionReason: null,
        userId: null,
        deptId: null,
        lastUpdateTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        idCardNumber: [
          {
            required: true,
            message: '身份证号码不能为空',
            trigger: 'blur'
          },
          {
            pattern: /^(^[1-9]\d{7}(\d{2}[0-9]{3}|[0-9]{3})$|^[1-9]\d{5}(18|19|20)?\d{2}\d{2}\d{2}(\d|X)$)/,
            message: '身份证号码格式不正确',
            trigger: 'blur'
          }
        ],
        name: [
          {
            required: true,
            message: '姓名不能为空',
            trigger: 'blur'
          },
          {
            pattern: /^[\u4e00-\u9fa5]{2,}$/,
            message: '姓名不能包含英文字母',
            trigger: 'blur'
          }
        ],
        studentId: [
          {
            required: true,
            message: '学号不能为空',
            trigger: 'blur'
          },
          {
            pattern: /^[ABS]\d{8}$/, // 学号格式: A或B或S开头，后面跟8位数字
            message: '学号格式不正确，必须以A、B或S开头，后面跟8位数字',
            trigger: 'blur'
          }
        ],
        scholarshipAmount: [
          {
            required: true,
            message: '金额不能为空',
            trigger: 'blur'
          },
          {
            pattern: /^\d+(\.\d{1,2})?$/, // 金额格式: 0.00、100、100.00等
            message: '金额格式不正确，必须为数字，并且可以包含最多两位小数',
            trigger: 'blur'
          }
        ]
      }

    }
  },
  created() {
    this.getList();
  },
  methods: {
    // 打开审核对话框
    openAuditDialog() {
      if (this.ids != null) {
        this.auditDialogVisible = true; // 显示审核对话框
        this.$refs['audit'].setData(this.ids);
      }
      else
        this.$message.error("请选择要审核的信息");
    },
    // 提交审核数据
    async handleAuditSubmit() {
      this.auditDialogVisible = false; // 关闭审核对话框
      await this.getList(); // 刷新数据列表
    },
    /** 查询学生资助信息列表 */
    getList() {
      this.loading = true;
      listStudentFinancial(this.queryParams).then(response => {
        this.studentFinancialList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        studentId: null,
        sfId: null,
        schoolName: null,
        departmentName: null,
        academicStage: null,
        major: null,
        educationLevel: null,
        studyDuration: null,
        enrollmentDate: null,
        name: null,
        gender: null,
        ethnicity: null,
        politicalStatus: null,
        idCardNumber: null,
        homeLocation: null,
        povertyType: null,
        otherDifficultyType: null,
        difficultyLevel: null,
        scholarshipLevel: null,
        scholarshipAmount: null,
        isExpansion: null,
        isVeteran: null,
        isScholarship: null,
        orientationType: null,
        fundingReason: null,
        auditStatus: null,
        rejectionReason: null,
        userId: null,
        deptId: null,
        lastUpdateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.sfId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加学生资助信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const sfId = row.sfId || this.ids
      getStudentFinancial(sfId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改学生资助信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.sfId != null) {
            updateStudentFinancial(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStudentFinancial(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const sfIds = row.sfId || this.ids;
      this.$modal.confirm('是否确认删除学生资助信息编号为"' + sfIds + '"的数据项？').then(function () {
        return delStudentFinancial(sfIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('studentFinancial/studentFinancial/export', {
        ...this.queryParams
      }, `studentFinancial_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
